package com.jjwxc.jwjskandriod.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jjwxc.jwjskandriod.R;
import com.jjwxc.jwjskandriod.config.YtApplication;
import com.jjwxc.jwjskandriod.framework.utils.FFUtils;

public class UploadDialog extends Dialog {
    private Context context;
    private ProgressBar progressBar;
    private TextView tv_progress;
    private TextView tv_title;
    private String title;

    public UploadDialog(Context context, String title) {
        super(context, R.style.my_dialog);
        this.context = context;
        this.title = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.upload_dialog);
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();
        lp.width = (FFUtils.getDisWidth() / 6 * 4); // 设置宽度
        lp.height = (FFUtils.getDisWidth() / 3); // 设置宽度
        this.getWindow().setAttributes(lp);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        tv_progress = (TextView) findViewById(R.id.tv_progress);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText(title);
    }

    public void setProgressBar(final int progress) {
        progressBar.setProgress(progress);
        YtApplication.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tv_progress.setText(progress + "%");
            }
        });
    }

}